package com.yunshang.shoppingmall.service.Finace.impl;


import com.yunshang.shoppingmall.entity.Finace.Finace;
import com.yunshang.shoppingmall.entity.FinaceToData;
import com.yunshang.shoppingmall.entity.FinaceTotal;
import com.yunshang.shoppingmall.entity.OrderToData;
import com.yunshang.shoppingmall.mapper.Finace.FinaceMapper;
import com.yunshang.shoppingmall.service.Finace.FinaceService;
import com.yunshang.shoppingmall.service.Finace.FinaceTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/*@Transactional*/
@Service("FinaceService")
public class FinaceServiceImpl implements FinaceService {

    @Autowired
    FinaceMapper finaceMapper;

    @Autowired
    FinaceTotalService finaceTotalService;

    @Override
    public List<Finace> selectFinaceList(int classify) {
        return finaceMapper.selectFinaceList(classify);
    }

    @Override
    public List<Finace> selectFinaceListUserNo(int classify,String userNo) {
        return finaceMapper.selectFinaceListUserNo(classify,userNo);
    }

    @Override
    public BigDecimal selectByPrimaryUserId(int classify,int userId) {
        return finaceMapper.selectByPrimaryUserId(classify,userId);
    }

    @Override
    public Finace selectFinaceAll(Integer userId) {
        return finaceMapper.selectFinaceAll(userId);
    }

    @Override
    public Finace selectFinaceByUserId(int userId) {
        return finaceMapper.selectFinaceByUserId(userId);
    }

    @Override
    public List<Finace> selectFinaceDetailsByUserId(FinaceToData finaceToData) {
        return finaceMapper.selectFinaceDetailsByUserId(finaceToData);
    }

    @Override
    public int updateBalanceByUserId(Finace finace) {
        return finaceMapper.updateBalanceByUserId(finace);
    }

    @Override
    public List<Finace> selectFinaceListUserNoId(OrderToData orderToData) {
        return finaceMapper.selectFinaceListUserNoId(orderToData);
    }

    @Override
    public int insertFinaceData(FinaceToData finaceToData) {
        return finaceMapper.insertFinaceData(finaceToData);
    }

    @Override
    public List<Finace> selectFinaceByUserIdAndFinaceType(OrderToData orderToData) {
        return finaceMapper.selectFinaceByUserIdAndFinaceType(orderToData);
    }

    //增加财务信息
    @Override
    public int insert(Finace record) {

        return finaceMapper.insert(record);
    }

    //增加财务信息

    /**
     *
     * @param classify
     * @param amount
     * @param userId
     * @param remark
     * @param UID
     * @param AID
     * @param finaceType
     * @return
     */
    @Override
    public int insertFinace(int classify, BigDecimal amount, int userId, String remark,int UID,int AID,int finaceType) {
        return finaceMapper.insertFinace(classify,amount,userId,remark,UID,AID,finaceType);
    }

    //增加财务信息

    /**
     *
     * @param classify
     * @param amount
     * @param userId
     * @param remark
     * @param UID
     * @param AID
     * @param finaceType
     * @return
     */
    @Override
    public int insertTestFinace(int classify, BigDecimal amount, int userId, String remark,int UID,int AID,int finaceType) {

        FinaceTotal finaceTotal = finaceTotalService.selectFinaceTotal(userId,classify+"");
        if(finaceTotal==null)
        {
            return finaceMapper.insertFinaceTotalAdd(classify,amount,userId,remark,UID,AID,finaceType);
        }
        return finaceMapper.insertFinaceTotalSet(classify,amount,userId,remark,UID,AID,finaceType);
    }

}
